﻿Imports System.Data
Partial Class Egresados_Personas
    Inherits PaginaComun

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim obj As New Personas
        obj.CEDULA = TxtId.Value
        obj.TIP_DOC = CmbTipId.SelectedValue
        obj.LUG_EXP_DOC = TxtLugExp.Text
        obj.FEC_EXP_DOC = DtpFecExp.SelectedDate
        obj.PRIMER_APELLIDO = TxtApe1.Text
        obj.SEGUNDO_APELLIDO = TxtApe2.Text
        obj.PRIMER_NOMBRE = TxtNom1.Text
        obj.SEGUNDO_NOMBRE = TxtNom2.Text
        obj.LM = TxtLib.Text
        obj.DM = TxtDist.Text
        obj.TP = TxtTP.Text
        obj.ESTADO_CIVIL = CmbEstCivil.SelectedValue
        obj.GRUPO_SANGUINEO = CmbSangre.SelectedValue
        obj.RELIGION = CmbReligion.SelectedValue
        obj.SEXO = CmbSexo.SelectedValue
        obj.DPTO_NTO = CmbDptoNac.SelectedValue
        obj.MCPIO_NTO = CmbMunNac.SelectedValue
        obj.FECHA_NACIMIENTO = DtpFecNac.SelectedDate
        obj.DIRECCION = TxtDir.Text
        obj.TELEFONO = TxtTel.Text
        obj.CELULAR = TxtCel.Text
        obj.FAX = TxtFax.Text
        obj.EMAIL = TxtEmail.Text
        obj.DPTO_RESIDENCIA = CmbDptoUbi.SelectedValue
        obj.MUN_RESIDENCIA = CmbMunUbi.SelectedValue
        obj.IDPK = Me.Pk1
        Select Case Me.Oper
            Case "Nuevo"
                MsgModalPanel.Text = obj.Insert
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
            Case "Editar"
                MsgModalPanel.Text = obj.Update
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
        End Select
        Me.GridView1.DataBind()
        Me.MultiView1.ActiveViewIndex = 1
    End Sub

    Sub limpiar()
        
    End Sub

    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) 'Handles ImageButton2.Click
        Me.MultiView1.ActiveViewIndex = 1
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim obj As New Personas
        Select Case e.CommandName
            Case "Editar"
                Me.Oper = "Editar"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                GridView1.SelectedIndex = index
                Dim dt As DataTable = obj.GetbyPK(GridView1.DataKeys(index).Values(0).ToString())
                If dt.Rows.Count > 0 Then
                    Me.TxtId.Text = dt.Rows(0)("Cedula").ToString
                    Me.CmbTipId.SelectedValue = dt.Rows(0)("Tip_Doc").ToString
                    Me.TxtLugExp.Text = dt.Rows(0)("Lug_exp_doc").ToString
                    Me.DtpFecExp.SelectedDate = dt.Rows(0)("fec_exp_doc").ToString
                    Me.TxtNom1.Text = dt.Rows(0)("Primer_nombre").ToString
                    Me.TxtNom2.Text = dt.Rows(0)("Segundo_Nombre").ToString
                    Me.TxtApe1.Text = dt.Rows(0)("Primer_Apellido").ToString
                    Me.TxtApe2.Text = dt.Rows(0)("Segundo_Apellido").ToString
                    Me.TxtLib.Text = dt.Rows(0)("LM").ToString
                    Me.TxtDist.Text = dt.Rows(0)("DM").ToString
                    Me.CmbEstCivil.SelectedValue = dt.Rows(0)("Estado_Civil").ToString
                    Me.CmbSangre.SelectedValue = dt.Rows(0)("Grupo_Sanguineo").ToString
                    Me.CmbReligion.SelectedValue = dt.Rows(0)("Religion").ToString
                    Me.CmbSexo.SelectedValue = dt.Rows(0)("Sexo").ToString
                    Me.TxtTP.Text = dt.Rows(0)("TP").ToString
                    Me.CmbDptoNac.SelectedValue = dt.Rows(0)("Dpto_Nto").ToString
                    Me.CmbMunNac.SelectedValue = dt.Rows(0)("Mcpio_Nto").ToString
                    Me.DtpFecNac.SelectedDate = dt.Rows(0)("Fecha_Nacimiento").ToString
                    TxtDir.Text = dt.Rows(0)("Direccion").ToString
                    Me.TxtTel.Text = dt.Rows(0)("Telefono").ToString
                    Me.TxtCel.Text = dt.Rows(0)("Celular").ToString
                    Me.TxtFax.Text = dt.Rows(0)("Fax").ToString
                    Me.TxtEmail.Text = dt.Rows(0)("Email").ToString
                    Me.CmbDptoUbi.SelectedValue = dt.Rows(0)("Dpto_Residencia").ToString
                    Me.CmbMunUbi.SelectedValue = dt.Rows(0)("Mun_Residencia").ToString
                    Me.Pk1 = dt.Rows(0)("Cedula").ToString
                    Me.MultiView1.ActiveViewIndex = 0
                End If
            Case "Eliminar"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                GridView1.SelectedIndex = index
                Me.Pk1 = GridView1.DataKeys(index).Values(0).ToString()
                Me.ModalPopupExtender1.Show()
        End Select
    End Sub

    Protected Sub ImageButton3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton3.Click
        Me.Oper = "Nuevo"
        limpiar()
        Me.MultiView1.ActiveViewIndex = 0
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim obj As New Personas
        MsgModalPanel.Text = obj.Delete(Me.Pk1)
        If obj.lErrorG = False Then
            ImgRst.ImageUrl = "~/imagenes/good.png"
        Else
            ImgRst.ImageUrl = "~/imagenes/error.png"
        End If
        ModalPopup.Show()
        GridView1.DataBind()
    End Sub

    Protected Sub BtnVolver_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnVolver.Click
        Me.MultiView1.ActiveViewIndex = 1
    End Sub

    Protected Sub TxtId_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtId.TextChanged
        If Me.Oper = "Nuevo" Then
            Dim obj As New Personas
            Dim dt As Data.DataTable = obj.GetbyPK(TxtId.Text)
            If dt.Rows.Count > 0 Then
                MsgModalPanel.Text = "El sistema ha encontrado una persona registrada con el documento digitado"
                ModalPopup.Show()
                Me.TxtId.Text = dt.Rows(0)("Cedula").ToString
                Me.CmbTipId.SelectedValue = dt.Rows(0)("Tip_Doc").ToString
                Me.TxtLugExp.Text = dt.Rows(0)("Lug_exp_doc").ToString
                Me.DtpFecExp.SelectedDate = dt.Rows(0)("fec_exp_doc").ToString
                Me.TxtNom1.Text = dt.Rows(0)("Primer_nombre").ToString
                Me.TxtNom2.Text = dt.Rows(0)("Segundo_Nombre").ToString
                Me.TxtApe1.Text = dt.Rows(0)("Primer_Apellido").ToString
                Me.TxtApe2.Text = dt.Rows(0)("Segundo_Apellido").ToString
                Me.TxtLib.Text = dt.Rows(0)("LM").ToString
                Me.TxtDist.Text = dt.Rows(0)("DM").ToString
                Me.CmbEstCivil.SelectedValue = dt.Rows(0)("Estado_Civil").ToString
                Me.CmbSangre.SelectedValue = dt.Rows(0)("Grupo_Sanguineo").ToString
                Me.CmbReligion.SelectedValue = dt.Rows(0)("Religion").ToString
                Me.CmbSexo.SelectedValue = dt.Rows(0)("Sexo").ToString
                Me.TxtTP.Text = dt.Rows(0)("TP").ToString
                Me.CmbDptoNac.SelectedValue = dt.Rows(0)("Dpto_Nto").ToString
                Me.CmbMunNac.SelectedValue = dt.Rows(0)("Mcpio_Nto").ToString
                Me.DtpFecNac.SelectedDate = dt.Rows(0)("Fecha_Nacimiento").ToString
                TxtDir.Text = dt.Rows(0)("Direccion").ToString
                Me.TxtTel.Text = dt.Rows(0)("Telefono").ToString
                Me.TxtCel.Text = dt.Rows(0)("Celular").ToString
                Me.TxtFax.Text = dt.Rows(0)("Fax").ToString
                Me.TxtEmail.Text = dt.Rows(0)("Email").ToString
                Me.CmbDptoUbi.SelectedValue = dt.Rows(0)("Dpto_Residencia").ToString
                Me.CmbMunUbi.SelectedValue = dt.Rows(0)("Mun_Residencia").ToString
                Me.Pk1 = dt.Rows(0)("Cedula").ToString
                habilitar(False)
                Me.MultiView1.ActiveViewIndex = 0
                Me.ImageButton1.Enabled = False
            End If
        End If
    End Sub
    Sub habilitar(ByVal v As Boolean)
        Me.TxtId.Enabled = v
        Me.CmbTipId.Enabled = v
        Me.TxtLugExp.Enabled = v
        Me.DtpFecExp.Enabled = v
        Me.TxtNom1.Enabled = v
        Me.TxtNom2.Enabled = v
        Me.TxtApe1.Enabled = v
        Me.TxtApe2.Enabled = v
        Me.TxtLib.Enabled = v
        Me.TxtDist.Enabled = v
        Me.CmbEstCivil.Enabled = v
        Me.CmbSangre.Enabled = v
        Me.CmbReligion.Enabled = v
        Me.CmbSexo.Enabled = v
        Me.TxtTP.Enabled = v
        Me.CmbDptoNac.Enabled = v
        Me.CmbMunNac.Enabled = v
        Me.DtpFecNac.Enabled = v
        TxtDir.Enabled = v
        Me.TxtTel.Enabled = v
        Me.TxtCel.Enabled = v
        Me.TxtFax.Enabled = v
        Me.TxtEmail.Enabled = v
        Me.CmbDptoUbi.Enabled = v
        Me.CmbMunUbi.Enabled = v
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            CompareValidator4.ValueToCompare = Today
            CompareValidator5.ValueToCompare = Today
            Me.DtpFecExp.SelectedDate = Today
            Me.DtpFecNac.SelectedDate = Today
        End If
    End Sub
End Class
